export function unitConvert(num = 0) {
  let moneyUnits = ["元", "万", "亿", "万亿"]
  let dividend = 10000
  let curentNum = num //转换数字
  let curentUnit = moneyUnits[0] //转换单位

  function strNumSize(tempNum) {
    let stringNum = tempNum.toString()
    let index = stringNum.indexOf(".")
    let newNum = stringNum
    if (index != -1) {
      newNum = stringNum.substring(0, index)
    }
    return newNum.length
  }

  for (let i = 0; i < 4; i++) {
    curentUnit = moneyUnits[i]
    if (strNumSize(curentNum) < 5) {
      break;
    }
    curentNum = curentNum / dividend
  }
  let m = {num: 0, unit: ""}
  m.num = curentNum.toFixed(2)
  m.unit = curentUnit
  return m
}


// 隐藏手机号码
export function hidePhoneNumber(str, n) {
  let searchValue = null
  let replaceValue = ''
  if (n === 7) {
    searchValue = /(\d{2})\d{7}(\d{2})/
    replaceValue = '$1*******$2'
  } else {
    searchValue = /(\d{3})\d{4}(\d{4})/
    replaceValue = '$1****$2'
  }
  return str.replace(searchValue, replaceValue)
}

// 删除数组指定元素
export function arrayRemove(arr, val) {
  let index = arr.indexOf(val);
  if (index > -1) {
    arr.splice(index, 1);
  }
}